Crate rend

source
Expand description

§rend

rend provides cross-platform, endian-aware primitives for Rust.

rend does not provide cross-platform alternatives for types that are inherently cross-platform, such as bool and u8. It also does not provide cross-platform alternatives for types that have an architecture-dependent size, such as isize and usize. rend does not support custom types.

rend is intended to be used to build portable types that can be shared between different architectures.

§Features

  • bytecheck: Enables support for validating types using bytecheck.

§Crates

  • zerocopy-0_8

§Example:

use core::mem::transmute;
use rend::*;

let little_int = i32_le::from_native(0x12345678);
// Internal representation is little-endian
assert_eq!(
    [0x78, 0x56, 0x34, 0x12],
    unsafe { transmute::<_, [u8; 4]>(little_int) }
);

// Can also be made with `.into()`
let little_int: i32_le = 0x12345678.into();
// Still formats correctly
assert_eq!("305419896", format!("{}", little_int));
assert_eq!("0x12345678", format!("0x{:x}", little_int));

let big_int = i32_be::from_native(0x12345678);
// Internal representation is big-endian
assert_eq!(
    [0x12, 0x34, 0x56, 0x78],
    unsafe { transmute::<_, [u8; 4]>(big_int) }
);

// Can also be made with `.into()`
let big_int: i32_be = 0x12345678.into();
// Still formats correctly
assert_eq!("305419896", format!("{}", big_int));
assert_eq!("0x12345678", format!("0x{:x}", big_int));

Modules§

  • Cross-platform primitives with unaligned representations.

Structs§

  • A big-endian AtomicI16 with a guaranteed size and alignment of 2.
  • A little-endian AtomicI16 with a guaranteed size and alignment of 2.
  • A big-endian AtomicI32 with a guaranteed size and alignment of 4.
  • A little-endian AtomicI32 with a guaranteed size and alignment of 4.
  • A big-endian AtomicI64 with a guaranteed size and alignment of 8.
  • A little-endian AtomicI64 with a guaranteed size and alignment of 8.
  • A big-endian AtomicU16 with a guaranteed size and alignment of 2.
  • A little-endian AtomicU16 with a guaranteed size and alignment of 2.
  • A big-endian AtomicU32 with a guaranteed size and alignment of 4.
  • A little-endian AtomicU32 with a guaranteed size and alignment of 4.
  • A big-endian AtomicU64 with a guaranteed size and alignment of 8.
  • A little-endian AtomicU64 with a guaranteed size and alignment of 8.
  • A big-endian NonZeroI16 with a guaranteed size and alignment of 2.
  • A little-endian NonZeroI16 with a guaranteed size and alignment of 2.
  • A big-endian NonZeroI32 with a guaranteed size and alignment of 4.
  • A little-endian NonZeroI32 with a guaranteed size and alignment of 4.
  • A big-endian NonZeroI64 with a guaranteed size and alignment of 8.
  • A little-endian NonZeroI64 with a guaranteed size and alignment of 8.
  • A big-endian NonZeroI128 with a guaranteed size and alignment of 16.
  • A little-endian NonZeroI128 with a guaranteed size and alignment of 16.
  • A big-endian NonZeroU16 with a guaranteed size and alignment of 2.
  • A little-endian NonZeroU16 with a guaranteed size and alignment of 2.
  • A big-endian NonZeroU32 with a guaranteed size and alignment of 4.
  • A little-endian NonZeroU32 with a guaranteed size and alignment of 4.
  • A big-endian NonZeroU64 with a guaranteed size and alignment of 8.
  • A little-endian NonZeroU64 with a guaranteed size and alignment of 8.
  • A big-endian NonZeroU128 with a guaranteed size and alignment of 16.
  • A little-endian NonZeroU128 with a guaranteed size and alignment of 16.
  • A big-endian u32 with a guaranteed size and alignment of 4.
  • A little-endian u32 with a guaranteed size and alignment of 4.
  • A big-endian f32 with a guaranteed size and alignment of 4.
  • A little-endian f32 with a guaranteed size and alignment of 4.
  • A big-endian f64 with a guaranteed size and alignment of 8.
  • A little-endian f64 with a guaranteed size and alignment of 8.
  • A big-endian i16 with a guaranteed size and alignment of 2.
  • A little-endian i16 with a guaranteed size and alignment of 2.
  • A big-endian i32 with a guaranteed size and alignment of 4.
  • A little-endian i32 with a guaranteed size and alignment of 4.
  • A big-endian i64 with a guaranteed size and alignment of 8.
  • A little-endian i64 with a guaranteed size and alignment of 8.
  • A big-endian i128 with a guaranteed size and alignment of 16.
  • A little-endian i128 with a guaranteed size and alignment of 16.
  • A big-endian u16 with a guaranteed size and alignment of 2.
  • A little-endian u16 with a guaranteed size and alignment of 2.
  • A big-endian u32 with a guaranteed size and alignment of 4.
  • A little-endian u32 with a guaranteed size and alignment of 4.
  • A big-endian u64 with a guaranteed size and alignment of 8.
  • A little-endian u64 with a guaranteed size and alignment of 8.
  • A big-endian u128 with a guaranteed size and alignment of 16.
  • A little-endian u128 with a guaranteed size and alignment of 16.